/*
 * @Author: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @Date: 2025-08-24 18:25:16
 * @LastEditors: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @LastEditTime: 2025-08-29 00:36:08
 * @FilePath: \keep_motion_manger\src\utils\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// 下载 blob 数据
export function useDownBlob(res, defultName) {
    const disposition = res.headers['content-disposition'];
    let fileName = defultName;
    if (disposition) {
        const match = disposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
        if (match != null && match[1]) {
            fileName = decodeURIComponent(match[1].replace(/['"]/g, ''));
        }
    }

    const blob = new Blob([res.data], { type: res.headers['content-type'] });
    const url = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = fileName;
    a.click();
    window.URL.revokeObjectURL(url);
};

// 调整path数组
export function adjustPath(paths, parentPath = '') {
    const newPaths = [];
    paths.forEach(item => {
        const newPath = `${parentPath}/${item.path}`;
        const newItem = {
            id: item.path,
            meta: {
                title: item.name,
                icon: item.icon,
            },
            path: newPath,
            hasChildren: item.children.length > 0,
            children: adjustPath(item.children, newPath),
        };
        newPaths.push(newItem);
    })
    return newPaths;
}